﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.DataAccess;

namespace University.Workshop.Business
{
    public class ManagerPerson
    {
        public static void UpdatePersonIfExisteElseCreate(Model.Person newPerson)
        {
            if (DataAccessPerson.GetPersonsById(newPerson).Count == 0)
            {
                DataAccessPerson.RegisterNewPerson(newPerson);
            }
            else
            {
                DataAccessPerson.UpdatePerson(newPerson);
            }
        }


        public static Model.Person GetPersonByPersonId(Model.Person person)
        {
            var persons = DataAccessPerson.GetPersonsById(person);
            if (persons.Count == 0)
                return null;
            else
                return persons.First();
        }

        public static void UpdatePerson(Model.Person modifyPerson)
        {
            DataAccessPerson.UpdatePerson(modifyPerson);
        }

        public static ICollection<Model.Person> SearchPersonByParameter(Model.Person p)
        {
            ICollection<Model.Person> persons = DataAccessPerson.SearchPersonByParameter(p);
            if (persons.Count == 0)
                throw new Exception("No se encontraron resultados de la busqueda...");
            
            return persons;
        }
    }
}
